<!-- Content Bar Header -->
<?php
$auth = Auth::getAuth('current_user');
$db = new Database();
$form_id = $_GET['id'];
if ($auth['user_level_id'] == "2") {
    echo $this->setInclude("contentHeader", null, null, null);
}
$company_id = $auth['company_id'];
$userCompany = new userQueries();
$search = new Search();


echo $_COOKIE['username'];
?>
<div class="content_wrapper">
    <div class="mainContent">
        <div>
            <?php
            if (isset($_POST['submit'])) {
                $location = $_FILES['fileupload']['tmp_name'];
                $return_array = import::importCSV($location);

                //echo $location;
                $headers = array();
                $fieldValues = array();
                foreach ($return_array as $key => $value) {
                    if ($key == 0) {
                        array_push($headers, $value);
                    } else {
                        array_push($fieldValues, $value);
                    }
                }

                $result = array();

                foreach ($fieldValues as $key => $value) {
                    $columnCount = count($headers);
                    $result = null;
                    foreach ($fieldValues[$key] as $key_1 => $value_1) {
                        $result[$headers[0][$key_1]] = $fieldValues[$key][$key_1];
                    }
                    print_r($result);
                    echo '<br/>';
                }
            }
            ?>
            <!--<form action ="/app" method="POST" enctype="multipart/form-data">-->
            <!--    <input type="file" name ="fileupload" />-->
            <!--    <input type="submit" name="submit" value="Submit"/>-->
            <!--</form>-->
            <div class="widget">
                <div class="head">
                    <div class="title_head">
                        <i class="icon-tasks"></i> Applications Category
                    </div>
                    <div class="pull-right" style="margin:5px;">
                    </div>
                </div>
                <br />

                  <?php

                     $forms_array = $db->query("SELECT ws.form_name as form_name, ws.id as id, ws.form_json as form_json
                                                              FROM tb_workspace ws
                                                              LEFT JOIN tbworkflow wf on ws.id = wf.form_id
                                                              WHERE wf.is_active = 1 and ws.is_active = 1
                                                              AND company_id = {$db->escape($auth[company_id])}
                                                              ORDER BY ws.form_name DESC","array");
                         $array_categoryID = array();
                          foreach ($forms_array as $forms) {
                                    
                                    $json =  json_decode($forms['form_json'],true);
                                    $formID = $forms['id'];
                                    $formName = $forms['form_name'];
                                    $forms = $json['form_json'];
                                    $categoryID = $json['categoryName'];
                                    
                                   array_push($array_categoryID,$categoryID);
                                 }
                               
                               //if(in_array("0",$array_categoryID)){
                               // echo "merong 0";
                               //  }
                     $getcategory = $db->query("SELECT * FROM tbform_category WHERE company_id = $company_id","array");
                        foreach($getcategory as $category){
                          if($category['users']!=""){
                            if($search->getFormPrivacyUsers($category['users'])==false){
                              continue;
                            }   
                          }
                           if(in_array($category['id'],$array_categoryID)){
                              $returnUL = '<div style="margin-left: 5px;">';
                                 $returnUL .= '<h3><i class="icon-folder-close"></i> ' . $category['category_name'] . '</h3>';
                              $returnUL .= '</div>';
                              $returnUL .= '<div style="padding: 5px;">';
                                 
                                 //echo in_array($category['id'],$array_categoryID);
                                $returnUL .= '<ul id="mycarousel" class="mycarousel jcarousel-skin-tango">';
                                $countForm = 0;
                                 // echo '<ul id="mycarousel" class="mycarousel jcarousel-skin-tango">';
                                    foreach ($forms_array as $forms) {
                                       
                                       $json =  json_decode($forms['form_json'],true);
                                       $formID = $forms['id'];
                                       $formName = $forms['form_name'];
                                       $forms = $json['form_json'];
                                       $categoryID = $json['categoryName'];
                                       $form_json = json_decode($json['form_json']);

                                       if($categoryID==$category['id']){
                                          if($json['form_json']['form-users']!=null){
                                            if($search->getFormPrivacyUsers(json_encode($json['form_json']['form-users']))==false){
                                              //continue;
                                            }
                                          }
                                          $countForm++;
                                          $returnUL .= '<li><div class=""><a href="/application?id=' . functions::base_encode_decode("encrypt",$formID). '" title="" class="cursor apps tip" id="form-' . $formID. '" data-placement="right" data-original-title="' . $formName. '">';

                                          $filename = 'images/formLogo/'.md5(md5($formID));
                                                      
                                             if( is_dir( $filename ) ) {
                                                $returnUL .= '<div style="width:61px;height:61px;"><img data-original-title="" src="/images/formLogo/'. md5(md5($formID)) .'/'.'small.png" width="61" height="61" class="avatar userAvatar formLogo" ></div>';
                                             } else {
                                                $returnUL .= '<div style="width:61px;height:61px;"><i class="icon-file" style="font-size: 61px;"></i></div>';
                                             }
                                          $returnUL .= '</a></div></li>';
                                       }
                                    }
                                 $returnUL .= '</ul>';
                              
                              $returnUL .= '</div>';
                              if($countForm>0){
                                echo $returnUL;
                              }
                           }
                        }
                  ?>
                  <?php
                     if(in_array(0,$array_categoryID)){
                  ?>
                     <div style="margin-left: 5px;">
                        <h3><i class="icon-folder-close"></i> Other Forms</h3>
                     </div>
                     <div style="padding: 5px;">
                        
                         <ul id="mycarousel" class="mycarousel jcarousel-skin-tango">
                           <?php
                            $forms_array = $db->query("SELECT ws.form_name as form_name, ws.id as id, ws.form_json as form_json
                                           FROM tb_workspace ws
                                           LEFT JOIN tbworkflow wf on ws.id = wf.form_id
                                           WHERE wf.is_active = 1 AND ws.is_active = 1
                                           AND company_id = {$db->escape($auth[company_id])}","array");
                 
                               foreach ($forms_array as $forms) {
                                  $json =  json_decode($forms['form_json'],true);
                                  $formID = $forms['id'];
                                  $formName = $forms['form_name'];
                                  $forms = $json['form_json'];
                                  $categoryID = $json['categoryName'];
                                  if($categoryID==0){
                                     echo '<li><div class=""><a href="/application?id=' . functions::base_encode_decode("encrypt",$formID). '" title="" class="cursor apps tip" id="form-' . $formID. '" data-placement="right" data-original-title="' . $formName. '">';
                                       $filename = 'images/formLogo/'.md5(md5($formID));
                                                
                                       if( is_dir( $filename ) ) {
                                          echo '<div style="width:61px;height:61px;"><img data-original-title="" src="/images/formLogo/'. md5(md5($formID)) .'/'.'small.png" width="61" height="61" class="avatar userAvatar formLogo"></div>';
                                       } else {
                                          echo '<div style="width:61px;height:61px;"><i class="icon-file" style="font-size: 61px;"></i></div>';
                                       }
                                     echo '</a></div></li>';
                                  }
                               }
                            ?>
                         </ul>
                         
                     </div>
                     <div class="hr"></div>
                  <?php
                     }
                  ?>
            </div>
        </div>
    </div>
   <?php
      // Company Announcement
         echo $this->setInclude("company_announcement",null,null,null);
         
      // Starred
         echo $this->setInclude("starred",null,null,null);
         
      // My Request
         echo $this->setInclude("my_request",null,null,null);
   
   ?>
</div>